<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>cookie</title>
</head>

<body>
    <button id="btn">存</button>
    <button id="get">取</button>
    <button id="del">删</button>
    <script>
        document.getElementById("btn").addEventListener("click", function () {
            document.cookie = "name=zhangsan; expires=Fri, 31 Dec 9999 23:59:59 GMT; path=/";
        });
        document.getElementById("get").addEventListener("click", function () {
            console.log(document.cookie)
        });
        document.getElementById("del").addEventListener("click", function () {
            document.cookie = "name=zhangsan; expires=Thu, 01 Jan 1970 00:00:00 GMT; path=/";
        });
    </script>
</body>

</html>